<template>
  <el-dialog
    :visible.sync="dialogVisible"
    width="800px"
    :before-close="handleClose"
    :close-on-click-modal="false"
    append-to-body
    :title="title"
  >
    <div
      style="
        margin-bottom: 30px;

        display: flex;
        justify-content: center;
        align-items: center;
      "
    >
      <div style="width: 680px">
        <el-descriptions :column="4" border>
          <el-descriptions-item label="退款金额" :span="4">{{
            form.receive_amount
          }}</el-descriptions-item>
          <el-descriptions-item label="订单金额" :span="4">{{
            form.amount
          }}</el-descriptions-item>
          <el-descriptions-item label="退款原因" :span="4">{{
            form.new_reason
          }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <!--   <table>
        <tr>
          <td>退款金额</td>
          <td>{{ form.receive_amount }}</td>
        </tr>
        <tr>
          <td>订单金额</td>
          <td></td>
        </tr>
        <tr>
          <td>退款原因</td>
          <td>{{ form.new_reason }}</td>
        </tr>
      </table> -->
    </div>
    <el-form :model="form" ref="formRef" label-width="120px">
      <el-form-item
        label="审核备注"
        prop="review_remake"
        :rules="[
          { required: true, message: '请输入审核备注', trigger: 'blur' },
        ]"
      >
        <el-input
          resize="none"
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4 }"
          placeholder="请输入"
          v-model="form.review_remake"
        ></el-input>
      </el-form-item>
      <!--     <el-form-item
        v-if="form.review_result == '通过'"
        label="退款比例(%)"
        prop="refund_percent"
        :rules="[
          { required: true, message: '请输入退款比例', trigger: 'blur' },
        ]"
      >
        <el-input
          type="input"
          placeholder="请输入"
          v-model="form.refund_percent"
        ></el-input>
      </el-form-item> -->

      <el-form-item
        label="退款状态"
        prop="review_result"
        :rules="[
          { required: true, message: '请选择退款状态', trigger: 'blur' },
        ]"
      >
        <el-radio v-model="form.review_result" label="通过">通过</el-radio>
        <el-radio v-model="form.review_result" label="不通过">不通过</el-radio>
      </el-form-item>

      <!--  <el-form-item
        label="职称"
        prop="position"
        :rules="[{ required: true, message: '请输入职称', trigger: 'blur' }]"
      >
        <el-input placeholder="请输入" v-model="form.position"></el-input>
      </el-form-item>
 -->
      <!--   <el-form-item
        label="所属科室"
        prop="department_id"
        :rules="[
          { required: true, message: '请选择所属科室', trigger: 'change' },
        ]"
      >
        <el-select
          v-model="form.department_id"
          clearable
          filterable
          placeholder="请选择"
        >
          <el-option
            v-for="item in departmentData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
 -->
      <!--    <el-form-item
        label="所属角色"
        prop="role_id"
        :rules="[
          { required: true, message: '请选择所属角色', trigger: 'change' },
        ]"
      >
        <el-select
          v-model="form.role_id"
          clearable
          filterable
          placeholder="请选择"
        >
          <el-option
            v-for="item in roleData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item> -->
      <!--  <el-form-item
        label="所属机构"
        prop="unit"
        :rules="[
          { required: true, message: '请输入所属机构', trigger: 'blur' },
        ]"
      >
        <el-input placeholder="请输入" v-model="form.unit"></el-input>
      </el-form-item> -->
    </el-form>
    <div slot="footer" class="tx-c">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="confirm('')" :loading="btnLoading"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { debounce } from "@/util";
import { ApiDoctorEdit, ApiOrderRefundHandle } from "@/api/index.js";
import ImgUploadPath from "@/components/imgUpload-path.vue";
import { validatePhone } from "@/util/validate";
export default {
  props: ["roleData", "departmentData"],
  components: {
    ImgUploadPath,
  },
  data() {
    return {
      validatePhone,
      optionsData: [
        { name: "男", code: "男" },
        { name: "女", code: "女" },
      ],
      levelArr: [
        { name: "普通", code: "普通" },
        { name: "中级", code: "中级" },
        { name: "高级", code: "高级" },
      ],

      oldform: {
        review_remake: "",
        refund_percent: "",
        /*     review_result: "通过", */
        receive_amount: "",
        amount: "",
        new_reason: "",
        /*    unit: "京山市人民医院", */
      },
      form: {
        review_result: "通过",
      },
      btnLoading: false,
      dialogVisible: false,
      id: null,
      title: "",
      imgsDefalut: [],
    };
  },

  methods: {
    onUploadSuccess(path) {
      console.log("111", path);
      this.form.icon = path;
    },
    onUploadRemove() {
      this.form.icon = "";
    },
    confirm: debounce(
      function (val) {
        this.$refs["formRef"].validate(async (valid) => {
          if (valid) {
            this.btnLoading = true;
            try {
              await ApiOrderRefundHandle(this.id, {
                ...this.form,
              });
              this.$message.success("修改成功");
              this.handleClose();
              this.$emit("refresh");
            } finally {
              this.btnLoading = false;
            }
          } else return false;
        });
      },
      500,
      true
    ),

    show(row) {
      const data = row || this.oldform;
      this.id = row.id;
      for (const key in this.oldform) {
        this.$set(this.form, key, data[key]);
      }
      console.log(this.form);

      /*   if(row.review_result=='待审核'){
        this.form
      }
     */
      /*  if (row) {
    
     
        if (row.file) {
          this.imgsDefalut = row.file.split(",");
        }
      } else {
        this.id = null;
        this.title = "添加人员";
      } */

      this.title = "审核数据";
      this.dialogVisible = true;
    },

    handleClose() {
      this.dialogVisible = false;
      this.form = { ...this.oldform };
      /*  this.$nextTick((_) => {
        this.$refs.formRef.clearValidate();
        this.$refs.ImgUploadPath.clear();
      }); */
    },
  },
};
</script>

<style></style>
